<?php
namespace app\widget\controller;

use tp5_lib\common\controller\TestBaseController;
use tp5_lib\menu\logic\Menu;
use DataWidget\widget\ListWidget;
use DataWidget\entity\ActionLink;

class TestController extends TestBaseController
{
    public function showMenu()
    {
        $this->assign("menu",Menu::get("template"));
        return $this->fetch("base/menu");
    }
    public function showFilter()
    {
        $items=[
            ["code"=>"filter_1","title"=>"名称","describe"=>"ID/name"],
            ["code"=>"filter_2","title"=>"标题","describe"=>"title"],
        ];

        $data=input();
        foreach($items as &$item){
            $item["value"] = isset($data[$item["code"]]) ? $data[$item["code"]] : "";
        }

        $this->assign("filter",["items"=>$items]);
        $this->assign("filter_actions",ActionLink::fillList([["title"=>"删除","href"=>url("delete")]]));
        return $this->fetch("base/filter");
    }
    public function showTable()
    {
        $list=ListWidget::alloc()->loadFields([
            ["code"=>"id","title"=>"ID"],
            ["code"=>"name","title"=>"名称"],
            ["code"=>"title","title"=>"标题"],
        ])
        ->setData([
            ["id"=>1,"name"=>"gfvedgfew","title"=>"hryhjthtr"],
            ["id"=>2,"name"=>"ewfewferg","title"=>"rhbrthtrw"],
        ])
        ->addAction("修改",function($item){
            return url("edit",["id"=>$item["id"]]);
        },"确认修改")
        ->setItemActions(function($item){
            return [ActionLink::create("复制",url("copy",["id"=>$item["id"]]))];
        })
        ->addFlag("selectable");
        $this->assign("multi_actions",[ActionLink::create("删除",url("delete"),"确认删除")->toArray()]);
        $this->assign("list",$list->toArray());
        return $this->fetch("base/table");
    }
    public function edit()
    {
        $this->success("编辑");
    }
    public function delete()
    {
        $this->result(input(),1);
    }
    public function copy()
    {
        $this->success("复制");
    }
}
